package com.token.zhuishushenqi.community.entity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * 动态热门的数据解析
 * Created by pengjianhuan on 2016/11/8 0008.
 */

public class DynamicHotJson {

    /**
     * _id : 57247427ed3da72654b04bfa
     * avatar : /avatar/4f/89/4f89ce2d54bfb34db0116e3e4e30bc7c
     * nickname : 柴浪
     * type : normal
     * lv : 7
     * gender : male
     */

    private UserBean user;
    /**
     * title : 你知道《西游记》被外国人翻译成什么吗？
     * content : 奇幻小说或曰神怪小说，涉及到妖魔与神仙的斗法，包罗了传统民间故事的很大一部分。这种传统与中国人的心灵非常接近。在中国人的心灵中，超自然的东西总是与现实纠缠在一起的。 《西游记》曾由田蒂莫西里查兹博士译出一个轮廓，书名为《天国求经记》，故事描述了玄奘法师去印度取经的业绩以及途中所遭遇的危险。 同行的还有三个极为可爱的半人半兽的人物：孙悟空、猪八戒和沙和尚。这个故事并不是由作家首创，而是以民间的宗
     * post : null
     * votes : []
     * deleted : false
     * isHot : true
     * score : 0
     * commented : 1
     * retweeted : 1
     * type : ARTICLE
     * created : 2016-11-10T05:21:14.153Z
     * _id : 582403ca5f352a1a54ce4391
     * hotAt : 2016-11-10T06:08:12.653Z
     * from : null
     * refTweet : null
     */

    private TweetBean tweet;

    public static DynamicHotJson objectFromData(String str) {

        return new Gson().fromJson(str, DynamicHotJson.class);
    }

    public static DynamicHotJson objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), DynamicHotJson.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<DynamicHotJson> arrayDynamicHotJsonFromData(String str) {

        Type listType = new TypeToken<ArrayList<DynamicHotJson>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<DynamicHotJson> arrayDynamicHotJsonFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<DynamicHotJson>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public UserBean getUser() {
        return user;
    }

    public void setUser(UserBean user) {
        this.user = user;
    }

    public TweetBean getTweet() {
        return tweet;
    }

    public void setTweet(TweetBean tweet) {
        this.tweet = tweet;
    }

    public static class UserBean {
        private String _id;
        private String avatar;
        private String nickname;
        private String type;
        private int lv;
        private String gender;

        public static UserBean objectFromData(String str) {

            return new Gson().fromJson(str, UserBean.class);
        }

        public static UserBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), UserBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<UserBean> arrayUserBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<UserBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<UserBean> arrayUserBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<UserBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public String get_id() {
            return _id;
        }

        public void set_id(String _id) {
            this._id = _id;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }

        public String getNickname() {
            return nickname;
        }

        public void setNickname(String nickname) {
            this.nickname = nickname;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public int getLv() {
            return lv;
        }

        public void setLv(int lv) {
            this.lv = lv;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }
    }

    public static class TweetBean {
        private String title;
        private String content;
        private Object post;
        private boolean deleted;
        private boolean isHot;
        private int score;
        private int commented;
        private int retweeted;
        private String type;
        private String created;
        private String _id;
        private String hotAt;
        private Object from;
        private Object refTweet;
        private List<?> votes;

        public static TweetBean objectFromData(String str) {

            return new Gson().fromJson(str, TweetBean.class);
        }

        public static TweetBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), TweetBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<TweetBean> arrayTweetBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<TweetBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<TweetBean> arrayTweetBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<TweetBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getJSONObject(key).toString(), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public Object getPost() {
            return post;
        }

        public void setPost(Object post) {
            this.post = post;
        }

        public boolean isDeleted() {
            return deleted;
        }

        public void setDeleted(boolean deleted) {
            this.deleted = deleted;
        }

        public boolean isIsHot() {
            return isHot;
        }

        public void setIsHot(boolean isHot) {
            this.isHot = isHot;
        }

        public int getScore() {
            return score;
        }

        public void setScore(int score) {
            this.score = score;
        }

        public int getCommented() {
            return commented;
        }

        public void setCommented(int commented) {
            this.commented = commented;
        }

        public int getRetweeted() {
            return retweeted;
        }

        public void setRetweeted(int retweeted) {
            this.retweeted = retweeted;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getCreated() {
            return created;
        }

        public void setCreated(String created) {
            this.created = created;
        }

        public String get_id() {
            return _id;
        }

        public void set_id(String _id) {
            this._id = _id;
        }

        public String getHotAt() {
            return hotAt;
        }

        public void setHotAt(String hotAt) {
            this.hotAt = hotAt;
        }

        public Object getFrom() {
            return from;
        }

        public void setFrom(Object from) {
            this.from = from;
        }

        public Object getRefTweet() {
            return refTweet;
        }

        public void setRefTweet(Object refTweet) {
            this.refTweet = refTweet;
        }

        public List<?> getVotes() {
            return votes;
        }

        public void setVotes(List<?> votes) {
            this.votes = votes;
        }
    }
}
